package uk.ac.lkl.lpp.model.xml;



import java.util.Map;

import org.w3c.dom.Document;
import org.w3c.dom.Element; //import org.w3c.dom.NodeList;


import uk.ac.lkl.common.util.ds.AbstractNotifyingList;
import uk.ac.lkl.common.util.ds.ListHandle;
import uk.ac.lkl.common.util.ds.NotifyingList;

import uk.ac.lkl.lpp.model.PedagogyPlanModel;


/**
 * Note that this class is currently unused.
 * 
 * It is intended to be used (eventually) as a replacement for a variety of list
 * processing processors (!)
 * 
 * @author Darren Pearce
 * @version $Revision$
 * @version $Date$
 * 
 */
public class ListProcessor extends ModelElementProcessor {

    public ListProcessor() {
        super("List");
    }


    /**
     * Convert all lists in the model to the appropriate elements.
     * 
     * This gets all the stored lists in the model and converts them in turn.
     * 
     */
    public void convertDataToElements(PedagogyPlanModel model,
                                      Document document,
                                      Element pedagogyPlanElement) {
        Map<ListHandle, AbstractNotifyingList> lists = model.getListMap();

        for (Map.Entry<ListHandle, AbstractNotifyingList> entry : lists.entrySet()) {
            ListHandle listHandle = entry.getKey();
            String name = listHandle.getName();
            Class itemClass = listHandle.getListClass();
            AbstractNotifyingList list = entry.getValue();
            convertListToElement(
                                 name,
                                 itemClass,
                                 list,
                                 document,
                                 pedagogyPlanElement);
        }
    }


    private void convertListToElement(String name,
                                      Class itemClass,
                                      AbstractNotifyingList list,
                                      Document document,
                                      Element pedagogyPlanElement) {
        Element parentElement = document.createElement("List");
        pedagogyPlanElement.appendChild(parentElement);

        for (int i = 0; i < list.size(); i++) {
            Object listElement = list.get(i);

            Element childElement = document.createElement("Item");
            // todo: finish this off
        }
    }


    public void convertElementToData(PedagogyPlanModel plan, Element element) {
        String className = element.getAttribute("itemClass");
    }

}
